package com.gitee.chenyaohua.oa.util.io;

import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.springframework.util.StringUtils;

public class IOUtil {

	
	public static String readFull(InputStream inputStream) {
		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
		StringBuilder str = new StringBuilder();
		String readLine = "";
		try {
			while((readLine = bufferedReader.readLine())!=null) {
				str.append(readLine);
			}
			
			bufferedReader.close();
			inputStream.close();
		} catch (IOException e) {
			e.printStackTrace();
		}finally {
			close(bufferedReader);
			close(inputStream);
		}
		return StringUtils.hasText(str.toString())? str.toString() :null;
	}
	
	
	public static void close(Closeable input) {
		try {
			if(input != null ) {
				input.close();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
